﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DisplayBoardInfo.Client.Forms;
using System.Windows.Forms;

namespace DisplayBoardInfo.Client
{
    public class  NetworkClientClass
    {
        private Network.Client c = new Network.Client();

        public Network.Client C { get { return this.c; } }

        public NetworkClientClass()
        {
            string ipNumber = Properties.Settings.Default.IpNumber;
            bool status = false;
            do
            {
                try
                {
                    c.Connect(ipNumber);
                    status = true;
                    Properties.Settings.Default.IpNumber = ipNumber;
                    Properties.Settings.Default.Save();
                }
                catch (Network.ClientException)
                {
                    IpNumberForm ipForm = new IpNumberForm();
                    ipForm.IPNumber = ipNumber;
                    if (ipForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ipNumber = ipForm.IPNumber;
                    }
                    else
                    {
                        status = true;
                        Application.Exit();
                    }
                }
            } while (!status);
        }

        public void Send(Network.Messages.NetworkMessage networkMessage)
        {
            c.Send(networkMessage);
        }
    }
}
